﻿using NoteBook_Product.DialogsService;
using NoteBook_Product.Events;
using Prism.Events;
using Prism.Services.Dialogs;

namespace NoteBook_Product.Extensions
{
    public static class DialogExtensions
    {
        /// <summary>
        /// 发布消息
        /// </summary>
        /// <param name="eventAggregator"></param>
        /// <param name="updateModel"></param>
        public static void UpdateLoading(this IEventAggregator eventAggregator, UpdateModel updateModel)
        {
            eventAggregator.GetEvent<UpdateLoadingEvent>().Publish(updateModel);
        }

        /// <summary>
        /// 订阅消息
        /// </summary>
        /// <param name="eventAggregator"></param>
        /// <param name="updateModel"></param>
        public static void UpdateLoading(this IEventAggregator eventAggregator, Action<UpdateModel> action)
        {
            eventAggregator.GetEvent<UpdateLoadingEvent>().Subscribe(action);
        }

        /// <summary>
        /// 询问窗口提示
        /// </summary>
        /// <param name="dialogHost"></param>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>
        public static async Task<IDialogResult> Question(this IDialogHostService dialogHost, string title, string content, string dialogHostName = "Root")
        {
            DialogParameters dialogParameters = new DialogParameters();
            dialogParameters.Add("Title", title);
            dialogParameters.Add("Content", content);
            dialogParameters.Add("DialogHostName", dialogHostName);
            var dialogResult = await dialogHost.ShowDialog("MsgView", dialogParameters, dialogHostName);
            return dialogResult;
        }
    }
}
